#ifndef ARKTS_OBJECT_MANAGER_H
#define ARKTS_OBJECT_MANAGER_H

#include "napi/native_api.h"
#include <string>
#include <vector>
#include <map>
#include <mutex>
#include <uv.h>
#include <functional>
#include "aki/jsbind.h"

namespace napiT {

struct AsyncWorkData {
    uv_async_t async;
    std::string prototypeName;
    std::vector<void*> params;
    napi_ref resultRef = nullptr;
    std::function<void(napi_ref)> callback;
};

struct Jsobject {
    napi_ref ref;
    std::string name;
};

extern std::map<std::string, Jsobject> jsobjectMap;
extern std::mutex jsobjectMapMutex;

extern napi_env g_jsEnv;
extern uv_loop_t* g_jsLoop;

std::string napiValueToString(napi_env env, napi_value value);
int napiValueToInt(napi_env env, napi_value value);
napi_value charValueToNapi(napi_env env, const char *str);
napi_value intValueToNapi(napi_env env, int32_t num);

napi_ref CreateObjectCrossThread(
    const std::string& key, 
    const std::vector<void*>& params,
    std::function<void(napi_ref)> callback
);

napi_value initArkTsObject(
    napi_env env, 
    const std::string &key, 
    napi_value &result, 
    const std::vector<void *> &params
);

void dialog(napi_ref &result);

} // namespace napiT

#endif // ARKTS_OBJECT_MANAGER_H
